package com.mgface.completableFuture;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;

import static java.lang.System.*;

public class DateDemo {

	public static void main(String[] args) throws Exception {
		//Instant瞬间
		Instant start = Instant.now();
		Thread.sleep(1_00);
		Instant end = Instant.now();
		//Duration持续
		Duration duration = Duration.between(start, end);
		out.println(duration.toMillis());
		LocalDate date = LocalDate.now();//今天日期
		out.println(date);
		LocalDate composedate = LocalDate.of(2016, 1, 17);
		out.println(composedate);
		LocalDate modifydate = composedate.plusDays(1L);//添加一天
		out.println(modifydate);
		LocalDate minusdate = composedate.minusDays(10L);//减少10天
		out.println(minusdate);
		//withDayOfMonth将月份天数修改为指定的值，并返回一个新的LocalDate对象
		LocalDate ld1 = composedate.withDayOfMonth(31);
		out.println(ld1);
		//获得月份天数，年份天数，获得星期几
		out.println(ld1.getDayOfMonth()+"|"+ld1.getDayOfYear()+"|"+ld1.getDayOfWeek());
		out.println(ld1.getMonth()+"|"+ld1.getMonthValue());
		LocalDate ld3 = LocalDate.of(2016, 1, 1).plusDays(255);
		out.println(ld3);
		LocalDate ld4 = LocalDate.of(2016, 1, 1);
		System.out.println(ld4.getDayOfWeek());
		LocalDate ld5 = LocalDate.of(2016, 2, 28);
		out.println(ld4.until(ld5, ChronoUnit.DAYS));
		LocalDate ld2 = LocalDate.of(2016, 1, 1).with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
		out.println(ld2);
		//指定日期的上一个星期天是什么日期
		LocalDate ld6 = LocalDate.of(2016, 1, 1).with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
		out.println(ld6);
		//第2个工作日的星期天是几号
		LocalDate ld7 = LocalDate.of(2016, 1, 1).with(TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.SUNDAY));
		out.println(ld7);
		///////////////////////////////////////////////
		LocalTime localTime = LocalTime.now();
		System.out.println(localTime.toSecondOfDay());
		System.out.println((double)localTime.toSecondOfDay()/3600);
	}

}
